package com.gxljc.bear.crawler.util;

import com.gxljc.bear.crawler.base.DolphinCrawlerConsts;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * ExtractUtil
 *
 * @author tanghaitao
 * @date 16-3-18
 */
public class ExtractUtil {

	//抽取注意事项，摘要等信息
	//抽取为分段显示的对象时，都适用此方法
	public static String extractListObj(Object listObj) {
		if (listObj == null) return null;
		List<String> list = (List<String>) listObj;
		if (CollectionUtils.isEmpty(list)) return null;
		StringBuffer returnStr = new StringBuffer();
		for (String text : list) {
			if (HtmlUtil.checkImage(text)) {
				text = String.format(DolphinCrawlerConsts.DEFAULT_TEXT_IMAGE_FORMAT, text);
			}
			text = text.replaceAll("\n", DolphinCrawlerConsts.DEFAULT_LINE_BREAK_WORD);
			returnStr.append(text).append(DolphinCrawlerConsts.DEFAULT_LINE_BREAK_WORD);
		}
		return returnStr.toString();
	}
}
